﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using CommonTagTime.Business;
using CommonTagTime.ModelObject;
using CommonTagTime;


public partial class UserControl_Category : System.Web.UI.UserControl
{
    //---------------------------------------------
    public SitePage sp = new SitePage();

    //---------------------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string s = Request.RawUrl;
            ulProduct.Visible = s.Contains("/products");
            ulLeft.Visible = !ulProduct.Visible;

            ContentProduct objContentProduct = new ContentProduct();
            objContentProduct.OrderBy = busContentProduct.SORTORDER;
            objContentProduct.OrderDirection = "ASC";
            objContentProduct.PageSize = int.MaxValue;
            objContentProduct.CurrentPage = 1;
            //objContentProduct.OrderBy = busContentProduct.PAGEURL;
            //objContentProduct.OrderDirection = "ASC";
            objContentProduct.Condition = " PageUrl LIKE N'%products/%' AND Language = " + sp.GetCurrentLang().ToString();
            busContentProduct _busContentProduct = new busContentProduct();

            ContentProductCollection lstResult = _busContentProduct.List(objContentProduct);
            if (lstResult != null && lstResult.Count > 0)
            {
                rptCategory.DataSource = lstResult;
            }

            rptCategory.DataBind();
        }
    }

    protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        RepeaterItem item = e.Item;
        ContentProduct data = new ContentProduct();
        if ((item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
        {
            data = (ContentProduct)item.DataItem;
            if (data == null)
                return;

            Literal lit = (Literal)item.FindControl("litCate");
            if (lit != null)
            {
                string strUrl = data.PageURL.Substring(0, 1) != "/" ? "/" + data.PageURL : data.PageURL;
                lit.Text = string.Format(@"<li class=""{0}""><a href=""{1}"">{2}</a></li>", GetCSSClass(data.PageURL), strUrl, data.Name);
            }
        }
    }

    public string GetCSSClass(params string[] lstUrl)
    {
        string result = string.Empty;

        try
        {
            SitePage basePage = (SitePage)this.Page;
            string s = Request.RawUrl;
            foreach (string url in lstUrl)
            {
                if (s == "/" && s == url)
                {
                    result += " headerActive";
                }
                else if (url != "/" && s.ToLower().Contains(url))
                {
                    result += " headerActive";
                    break;
                }
            }
        }
        catch
        {

        }


        return result;
    }
}